package com.cskaoyan.controller;


import com.cskaoyan.bean.Coupon;
import com.cskaoyan.service.CouponService;
import com.cskaoyan.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CouponController {

    @Autowired
    CouponService couponService;
    @RequestMapping("admin/coupon/list")
    public BaseRespVo queryCoupon(Integer page, Integer limit, String name, Integer type,
                                  Integer status, String sort, String order){

     CouponVO couponVO = couponService.queryCoupon(page,limit,name,type,status,sort,order);
     return BaseRespVo.ok(couponVO);
    }
    @RequestMapping("admin/coupon/read")
    public BaseRespVo readCoupon(Integer id){
      Coupon coupon= couponService.readCoupon(id);
      return BaseRespVo.ok(coupon);
    }

    @RequestMapping("admin/coupon/listuser")
    public BaseRespVo queryUser(Integer page, Integer limit, Integer couponId, Integer userId, Integer status,
                                String sort, String order ){

        CouponUserVO couponUserVO = couponService.queryUser(page, limit, couponId, userId, status, sort, order);
        return BaseRespVo.ok(couponUserVO);

    }
    @RequestMapping("admin/coupon/create")
    public BaseRespVo createCoupon(@RequestBody Coupon coupon){
        Coupon coupons= couponService.createCoupon(coupon);
        return BaseRespVo.ok(coupons);
    }
    @RequestMapping("admin/coupon/delete")
    public BaseRespVo deleteCoupon(@RequestBody Coupon coupon){

        couponService.deleteCoupon(coupon);

        return BaseRespVo.ok();
    }
    @RequestMapping("admin/coupon/update")
    public BaseRespVo updateCoupon(@RequestBody Coupon coupon){
        Coupon coupons= couponService. updateCoupon(coupon);
        return BaseRespVo.ok(coupons);
    }
}
